<template>
    <div>
        <div>
            测试数量
            <el-input-number
                v-model="num"
                controls-position="right"
                :min="1"
                :max="50"
            ></el-input-number>
        </div>
        <div v-if="data && data.length !== 0" class="HTMLString">
            <h4 style="margin-bottom: 10px">生成结果：</h4>
            <p v-for="(item, i) in data" :key="i">{{ item }}</p>
        </div>
        <div style="text-align: right; margin-right: 35px">
            <el-button @click="handleCancel">取消</el-button>
            <el-button
                type="primary"
                @click="handleAddClick(num)"
                :loading="saveLoading"
            >
                确定
            </el-button>
        </div>
    </div>
</template>
<script>
import { getGenerateBatch } from '@/api/code/codeGeneration'

export default {
    data () {
        return {
            form: {},
            data: [],
            initfalse: false,
            num: 0,
            saveLoading: false, //按钮的加载
        }
    },

    methods: {
        // 初始化
        init (params) {
            if (params) {
                this.form = { ...params }
                console.log(this.form, 'this.form')
            } else {
                this.form = {}
            }
        },
        handleAddClick () {
            let params = {
                ruleCode: this.form.ruleCode,
                size: this.num,
            }
            this.saveLoading = true
            getGenerateBatch(params)
                .then((res) => {
                    this.saveLoading = false

                    if (res.code === 0) {
                        this.data = res.data || []
                    } else {
                        this.$$message.error('操作失败')
                    }
                })
                .catch(() => {
                    this.$$message.error('操作失败')
                    this.saveLoading = false
                })
        },
        // 关闭
        handleCancel () {
            this.num = 0
            this.data = []
            this.$emit('cancel', this.initfalse)
        },
    },
}
</script>
<style lang="scss" scoped>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.HTMLString {
    max-height: 200px;
    overflow-x: hidden;
    overflow-y: scroll;
    margin-top: 15px;
    margin-left: 60px;

    p {
        margin: 5px 0;
    }
}
</style>
